package com.zhanghu.hibernate.entity;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * @Author: zhanghu
 * @Description:
 * @Date: Create in 9:30 2020/1/7
 * @modified by:
 */
@Entity
@Table(name = "zk_user", schema = "mytest", catalog = "")
public class ZkUser {
    private Integer id;
    private String avatar;
    private String username;
    private String password;
    private String name;
    private Timestamp birthday;
    private Integer sex;
    private String email;
    private String phone;
    private Integer status;
    private Timestamp createTime;
    private Timestamp updateTime;


    private ZUser zUser;

    @OneToOne
    @JoinColumn(referencedColumnName = "user_id", name = "id")
    @Fetch(FetchMode.JOIN)
    @NotFound(action = NotFoundAction.IGNORE)
    public ZUser getzUser() {
        return zUser;
    }

    public void setzUser(ZUser zUser) {
        this.zUser = zUser;
    }

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "avatar", nullable = true, length = 255)
    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @Basic
    @Column(name = "username", nullable = true, length = 45)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "password", nullable = true, length = 96)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "name", nullable = true, length = 45)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "birthday", nullable = true)
    public Timestamp getBirthday() {
        return birthday;
    }

    public void setBirthday(Timestamp birthday) {
        this.birthday = birthday;
    }

    @Basic
    @Column(name = "sex", nullable = true)
    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    @Basic
    @Column(name = "email", nullable = true, length = 45)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic
    @Column(name = "phone", nullable = true, length = 45)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "status", nullable = true)
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Basic
    @Column(name = "create_time", nullable = true)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "update_time", nullable = true)
    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ZkUser zkUser = (ZkUser) o;
        return id.equals(zkUser.id) &&
                Objects.equals(avatar, zkUser.avatar) &&
                Objects.equals(username, zkUser.username) &&
                Objects.equals(password, zkUser.password) &&
                Objects.equals(name, zkUser.name) &&
                Objects.equals(birthday, zkUser.birthday) &&
                Objects.equals(sex, zkUser.sex) &&
                Objects.equals(email, zkUser.email) &&
                Objects.equals(phone, zkUser.phone) &&
                Objects.equals(status, zkUser.status) &&
                Objects.equals(createTime, zkUser.createTime) &&
                Objects.equals(updateTime, zkUser.updateTime);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, avatar, username, password, name, birthday, sex, email, phone, status, createTime, updateTime);
    }
}
